package com.shuai.orderfood.merchants.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.shuai.orderfood.common.Result;
import com.shuai.orderfood.merchants.pojo.MerchantsUser;
import com.shuai.orderfood.merchants.service.MerchantsUserService;
import com.shuai.orderfood.merchants.vo.MerchantsUserVo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/merchants/user")
public class MerchantsUserController {

    @Resource
    private MerchantsUserService merchantsUserService;

    //查询商家端的用户，支持根据关键字（用户名）搜索
    @GetMapping
    public Result<List<MerchantsUserVo>> getAll(@RequestParam(value = "keyword", required = false) String keyword,
                                                 @RequestParam("page") Integer page,
                                                 @RequestParam("limit") Integer limit) throws Exception {
        List<MerchantsUserVo> merchantsUserVoList = merchantsUserService.getAll(keyword, page, limit);
        return Result.success(merchantsUserVoList);
    }

    //根据id查询商家端的用户
    @GetMapping("/{id}")
    public Result<MerchantsUser> getMerchantsUserById(@PathVariable("id") Integer id) {
        return null;
    }

    /**
     * 根据id修改商家端的用户
     * MerchantsUserVo本是响应实体类，但是这里由于修改时的字段也是这些，因此直接复用该类。
     */
    @PutMapping("/modify")
    public Result modifyMerchantsUser(@RequestBody MerchantsUserVo merchantsUserVo) throws Exception {
        merchantsUserService.updateMerchantsUser(merchantsUserVo);
        return Result.success();
    }
}
